package flexconsole.controller {
	import flash.filesystem.File;
	
	import flexconsole.AppFacade;
	import flexconsole.utils.FileUtil;
	
	import mx.logging.ILogger;
	import mx.logging.Log;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * Shutdown command for the application.
	 *
	 * @author ivanchoo
	 *
	 */
	public class ShutdownCommand extends SimpleCommand {
		
		static private var logger:ILogger = Log.getLogger("flexconsole.controller.ShutdownCommand");
		
		override public function execute(notification:INotification):void {
			logger.debug("execute({0})", notification);
			super.execute(notification);
			
			//   Shutdown sequence
			try {
				var appFacade:AppFacade = facade as AppFacade;
				FileUtil.writeFileAsXML(File.applicationStorageDirectory.resolvePath(AppFacade.FILENAME_CONFIG), appFacade.configProxy.source);
				FileUtil.writeFileAsXML(File.applicationStorageDirectory.resolvePath(AppFacade.FILENAME_CATEGORY), appFacade.categoryProxy.source);
				FileUtil.writeFileAsXML(File.applicationStorageDirectory.resolvePath(AppFacade.FILENAME_LOG), appFacade.logMessageProxy.source);
			} catch (e:Error) {
				logger.error(e.message);
			}
		
		}
	}
}